package lex.dm.utils;

import java.awt.event.ActionEvent;
import java.lang.reflect.Method;
import java.sql.ResultSet;

import org.lex.swing.ActionBuilder;

import lex.dm.DTree;

public class ResultSetAction extends ActionBuilder
{
	private static final Object[] EMPTY = new Object[0];
	private final Method method;

	public ResultSetAction( Method method, String name )
	{
		this.method = method;
		this.setName( name );
	}

	@Override
	public void actionPerformed( ActionEvent e )
	{
		DTree app = DTree.getApplication();
		try
		{
			ResultSet rs = (ResultSet) method.invoke( app.getConnection().getMetaData(), EMPTY );
			app.getContentPane().addResultSet( this.getName(), rs );
		}
		catch( Exception e1 )
		{
			e1.printStackTrace();
		}
	}
}
